<% @page_title = "多背一公斤 | #{h @event.title}" %>

<% content_for :head do -%>
  <script type="text/javascript" src="/javascripts/thickbox.js"></script>
  <link rel="stylesheet" href="/stylesheets/thickbox.css" type="text/css" media="screen" />
<% end -%>

<% content_for :sidebar do -%>
<div>
	<h3 class="nt">参加这个活动的人 <%= title_suffix %></h3>
  <%= render :partial => "/shared/users", :object => @event.participators %>
</div>
<% end -%>

<h3 class="note"><%= h @event.title %></h3>

<% if @event.editable_by? current_user -%>
<p>
  <% unless @event.pic -%>
    <%= link_to "上传活动海报", new_pic_event_path(@event), :title => "一张可以代表性的海报可以让你的活动更有吸引力"  %> | 
  <% end -%>
  
  <%  if @event.school_id.nil? -%>
    <%= link_to "选择要去的学校", choice_school_event_path(@event), :title => "选择活动中要去的学校，加入多背一公斤活动" %> |
  <% else -%>
    <%= link_to "重新选择要去的学校", choice_school_event_path(@event), :title => "修改活动中要去的学校" %> |
  <% end -%>
  
  <%= link_to "修改活动", edit_event_path(@event.id) %> |
  <%= link_to "删除", event_path(@event.id), :method => :delete, :confirm => "你确定要删除么？" %>
</p>
<% end -%>


<div class= "span-8 prepend-1">
	<%= avatar_for @event.submitor, "small" %>
	<%= link_to @event.submitor.login, user_path(@event.submitor.id) %>
	<span class="tip">发起于：<%= show_datetime(@event.created_at, false) %></span>
</div>

<div class="span-4"><span class="tip">已参加人数：<%= @event.participators.count %></span><br /></div>

<div id="join_in" class="span-3 last">
  <% if @event.has_end? -%>
    <h4>活动已结束</h4>
  <% elsif logged_in? -%>
		<% if @event.participators.include?(current_user) -%>
			<h4><%= link_to "退出活动", quit_event_path(@event), :method => :put %></h4>
		<% else -%>
			<h4><%= link_to "我要参加", join_event_path(@event), :method => :put %></h4>
		<% end -%>
  <% else -%>
    <h4><%= link_to "我要参加", login_url %></h4>
  <% end -%>
</div>

<hr />

<h3 class="nt">活动概况 <%= title_suffix %></h3>
<div class="event span-8 prepend-1">
	<span>开始时间：</span><%= show_datetime(@event.start_at, false) %><br />
	<span>结束时间：</span><%= show_datetime(@event.end_at, false) %><br />
	<span>集合地点：</span><%= h @event.location %><br />
	<span>活动类型：</span><%= Event.categories[@event.category] %><br />
	<% unless @event.school_id.blank? -%>
	<span>要去的学校：</span><%= link_to @event.school.title, school_url(@event.school_id) %><br />
	<% end -%>
	<span>详细讨论：</span><%= @comments.size %> <span>(<a href="#comments">查看全部</a>)</span>
	<br />
	<br />
</div>
<div class="span-7 last">
	<%= image_tag(@event.pic.public_filename, :style => "margin: 0 10px 10px 10px") if @event.pic %>
</div>
<div class="clear"></div>

<div>
<h3 class="nt">活动内容 <%= title_suffix %></h3>
<%= @event.content_html %>
</div>

<a name="comments"></a>
<h3 class="nt"><%= '“'+ @event.title + '”' + "的讨论"%> <%= title_suffix %></h3>

<div>
	<% if @comments.blank? -%>
  	<p>还没人留言</p>
	<% end -%>

	<% @comments.each do |comment| -%>
	<div class="span-2 last">
		<%= avatar_for comment.user, "large" %>
	</div>
	<div class="span-13 last">		
		<div class="span-11 comment_label">
		  <%= link_to comment.user.login, user_path(comment.user) %>
  		写于：<span class="tip"><%= show_date comment.created_at %></span>
		</div>
		<div class="span-2 last">
			<% if comment.editable_by?(current_user) -%>
				<%= link_to "修改", event_edit_comment_path(@event, comment) %>
				<%= link_to "删除", event_comment_path(@event, comment), :method => 'delete', :confirm => "您确定要删除么？" %>
			<% end -%>
		</div>
		<div class="span-13"><%= comment.content_html %></div>
	</div>
	<% end -%>
</div>
<div class="clear"></div>

<a name="write-comment"></a>
<div>
<% if logged_in? -%>
  <h3 class="note">你的留言 <%= title_suffix %></h3>
  <% form_for :comment, :url => event_comments_path(:event_id => @event.id) do |f| -%>
		<%= render :partial => 'event_comments/form', :object => f, :locals => {:title => "Re:#{@event.title}"} %>
    <p><%= submit_tag "发表留言" %></p>
  <% end -%>
<% else -%>
  <%= link_to "登录", login_url %>后你也可以发表评论或留言
<% end -%>
</div>

<h3 class="nt">活动照片 <%= title_suffix %></h3>
<div class="span-3 last">
	<% if logged_in? && @event.participators.include?(current_user) -%>
	<h4><%= link_to "上传照片", new_photo_url(:event_id => @event.id) %></h4>
<% end -%>
</div>

<div class="span-15 prepend-1">
<% @photos.each do |photo| -%>
	<%= link_to image_tag(photo.public_filename(:small), :style => "border: 1px solid #666;padding:2px"), photo_url(photo) %>
<% end -%>
</div>
